package main

import (
	"fmt"
	"github.com/giorgisio/goav/avcodec"
	"github.com/giorgisio/goav/avformat"
	"github.com/giorgisio/goav/avdevice"
)

func main() {
	fmt.Println("hello word")
	var pFormatCtx *avformat.Context 
	var pCodecCtx *avformat.CodecContext
	var pCodec *avcodec.Codec

	avformat.AvRegisterAll()
	avformat.AvformatNetworkInit()
	pFormatCtx = avformat.AvformatAllocContext()

	//var ofmt_ctx *avformat.Context
	//var ifmt_ctx *avformat.Context
	//var ovCodecCtx *avformat.CodecContext
	//var ovCodec *avformat.AvCodec
	//var video_st *avformat.Stream
	//var audio_st *avformat.Stream

	//out_path := "rtmp://127.0.0.1:1935/live/test"
	avdevice.AvdeviceRegisterAll()

	res := avformat.AvformatOpenInput(&pFormatCtx, "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov", nil,nil)

	if res < 0 {
		fmt.Println("Couldn't open  input stream.")
	}
	res = avformat.AvformatFindStreamInfo(pFormatCtx,nil)

	if res <0 {
		fmt.Println("Couldn't find stream information.")
	}

	for _, v := range pFormatCtx.Streams() {
		if v.Codec().GetCodecType() == avformat.AVMEDIA_TYPE_VIDEO {
			fmt.Println("video stream get")
			pCodecCtx = v.Codec()
			break
		}
	}
	pCodec = avcodec.AvcodecFindDecoderEnum(pCodecCtx.GetCodecIdInt())
	
	if pCodec == nil {
		fmt.Println("Codec not found.")
	}
	res = pCodecCtx.AvcodecOpen2(pCodec,nil)

	pFormatCtx.AvDumpFormat(0,nil,0)






}